package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.Srecharge;
import cn.stylefeng.guns.modular.system.mapper.SrechargeMapper;
import cn.stylefeng.guns.modular.system.model.params.SrechargeParam;
import cn.stylefeng.guns.modular.system.model.result.SrechargeResult;
import  cn.stylefeng.guns.modular.system.service.SrechargeService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  服务实现类
 *  代充值
 * </p>
 *
 * @author yl
 * @since 2019-07-09
 */
@Service
public class SrechargeServiceImpl extends ServiceImpl<SrechargeMapper, Srecharge> implements SrechargeService {


    @Autowired
    private SrechargeMapper srechargeMapper;


    @Override
    public void add(SrechargeParam param){
        Srecharge entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(SrechargeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(SrechargeParam param){
        Srecharge oldEntity = getOldEntity(param);
        Srecharge newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public SrechargeResult findBySpec(SrechargeParam param){
        return null;
    }

    @Override
    public List<SrechargeResult> findListBySpec(SrechargeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(SrechargeParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(SrechargeParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Srecharge getOldEntity(SrechargeParam param) {
        return this.getById(getKey(param));
    }

    private Srecharge getEntity(SrechargeParam param) {
        Srecharge entity = new Srecharge();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }



    /**
     * 查询充值表和，充值分类表
     */
    public List<Srecharge> QuerySrecharge(){

        return srechargeMapper.QuerySrecharge();
    }


    /**
     * 查询详情
     */
    public List<SrechargeResult> QuerySrechargeId(String id){
        return srechargeMapper.QuerySrechargeId(id);
    }


    /**
     * 根据 id 修改数据信息
     */
    public int UpdateSrecharge(BigDecimal number , String type , String remarks , Integer id ){
        return srechargeMapper.UpdateSrecharge(number,type,remarks,id);
    }








}
